package com.erp.module.ProductionExecute.ProductionExecuteXx

import android.content.Context
import android.util.Log
import com.erp.Interface.OnUserDataInterface
import com.erp.module.ProductionExecute.ProductionExecuteM
import com.erp.module.ProductionExecute.ProdutionExecuteContract
import com.erp.module.caiLiaoZhiLiang.xGCaiLiaoZhiLiang.IXiugaiCailiaoZhiliangKP
import com.erp.util.JsonUtil
import com.erp.util.Myutil
import org.json.JSONObject

class productionExecuteActivityP(var KV : ProdutionExecuteContract.ProductionActivityKV, var context: Context): ProdutionExecuteContract.ProductionActivityKP {
    var md = ProductionExecuteM()
    override fun getIu() {
        var Ids: ArrayList<String> = ArrayList<String>()
        var Names: ArrayList<String> = ArrayList<String>()
        md.getGongyingshangLieBiao(context, object : OnUserDataInterface {
            override fun onUserData(data: String?) {
                if (data == null) {
                    return
                }
                IXiugaiCailiaoZhiliangKP.gongyingshangs = data
                ziliaojson(IXiugaiCailiaoZhiliangKP.gongyingshangs, Ids, Names)
                KV.getiu_names(Ids, Names)
            }

            override fun onNot(throwable: String?) {
                Log.d("TAAAG","th="+throwable.toString())

            }

        })
    }

    override fun setIu(plmdyhhid: String, iu_id: String) {
        md.setGongyingshang(context,plmdyhhid,iu_id,object :OnUserDataInterface{
            override fun onNot(throwable: String?) {
            }

            override fun onUserData(data: String?) {
                KV.gongyingxiugaiok()
                Myutil.MyTost("修改供应商成功")
            }

        })
    }

    //解析资料数据json
    fun ziliaojson(data: String, ids: ArrayList<String>, names: ArrayList<String>) = try {
        val jo = JSONObject(data)
        val keys = jo.keys()
        while (keys.hasNext()) {
            val key = keys.next() as String
            ids.add(key)
            names.add(JsonUtil.getvolue(jo, key))
        }
    } catch (e: Exception) {
        e.printStackTrace()
    }

}